package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.sql.Statement;

public class DbAccessSample {
	public static void main(String[] args){
		Connection con = null;
		PreparedStatement pstm = null;

		try{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			String jdbcurl = "jdbc:oracle:thin:@DIO:1521:LUCKYLAND";
            Properties props = new Properties();
                 props.put("user","ARAKI");
                 props.put("password","HIROHIKO");
                 props.put("useUnicode","true");
                 props.put("characterEncoding","SHIFT_JIS");
                con = DriverManager.getConnection( jdbcurl,props );

                String sql = "select 1 \"1\",sysdate \"2\" from dual";

                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery(sql);

                while( rs.next() ){
                     String no = rs.getString("1");
                     String price = rs.getString("2");
                     System.out.println(no + "  " + price);
                }

                stmt.close();
                con.close();
                System.out.println("接続成功");
                con.close();
              }catch( ClassNotFoundException ex ){
                      System.out.println("JDBCドライバのロードエラー");
                      ex.printStackTrace();
              } catch ( SQLException ex ) {
                      System.out.println("データベースアクセスエラー");
                      ex.printStackTrace();
              }catch( Exception ex ){
                      System.out.println("エラー");
                      ex.printStackTrace();
             }
       }
}
